/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wasolicitudesfiec.Administracion.AyudantiasVarias.dataproviders;

import com.sun.data.provider.DataProviderException;
import com.sun.data.provider.FieldKey;
import com.sun.data.provider.RowKey;
import com.sun.data.provider.impl.AbstractTableDataProvider;
import com.sun.data.provider.impl.IndexRowKey;
import entidad.Parametro;
import java.util.Vector;

/**
 *
 * @author Administrador
 */
public class Dp_AyudantiaVaria extends AbstractTableDataProvider {
	private Vector<Parametro> listaAyudantiasVarias;

	public Dp_AyudantiaVaria() {
		agregarKey("id", "Identificador");
		agregarKey("nombre", "Nombre");
		agregarKey("descripcion", "Descripción");
	}

	public void setListaAyudantiasVarias(Vector<Parametro> listaAyudantiasVarias) {
		this.listaAyudantiasVarias = listaAyudantiasVarias;
	}

	private void agregarKey(String key_string, String display_name) {
		FieldKey key;
		key = new FieldKey(key_string);
		key.setDisplayName(display_name);
		addFieldKey(key);
	}

	@Override
	public Class getType(FieldKey fieldKey) throws DataProviderException {
		return String.class;
	}

	@Override
	public boolean isReadOnly(FieldKey fieldKey) throws DataProviderException {
		return true;
	}

	@Override
	public int getRowCount() throws DataProviderException {
		if (listaAyudantiasVarias!=null)
			return listaAyudantiasVarias.size();
		else
			return 0;
	}

	@Override
	public Object getValue(FieldKey fieldKey, RowKey row) throws DataProviderException {
		int indice = ((IndexRowKey) row).getIndex();
		System.out.println("fieldKey:"+fieldKey);
		if (fieldKey==null)
			return "";
		String fieldId = fieldKey.getFieldId();
		System.out.println("index:" + indice + " fieldKey.getFieldId():" + fieldId);
		Parametro ayudantiaVaria = listaAyudantiasVarias.get(indice);
		if (fieldId.equals("id")){
			return ayudantiaVaria.getIdParametro();
		}else if (fieldId.equals("nombre")){
			return ayudantiaVaria.getNombre();
		}else if (fieldId.equals("descripcion")){
			return ayudantiaVaria.getDescripcion();
		}
		return fieldId+indice;
	}

	@Override
	public void setValue(FieldKey fieldKey, RowKey row, Object value) throws DataProviderException {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public boolean canInsertRow(RowKey beforeRow) throws DataProviderException {
		return false;
	}

	@Override
	public RowKey insertRow(RowKey beforeRow) throws DataProviderException {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public boolean canAppendRow() throws DataProviderException {
		return false;
	}

	@Override
	public RowKey appendRow() throws DataProviderException {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public boolean canRemoveRow(RowKey row) throws DataProviderException {
		return false;
	}

	@Override
	public void removeRow(RowKey row) throws DataProviderException {
		throw new UnsupportedOperationException("Not supported yet.");
	}
}
